package py.com.sole.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import py.com.sole.dao.DaoFactory;
import py.com.sole.model.Alumno;

@FacesConverter(value="alumnoConverter2")
public class AlumnoConverter2 implements Converter {

	@Override
	public Object getAsObject(FacesContext context, UIComponent component,
			String value) {
		
		if(value==null||value.equals("")){
            return null;
        }
		
		Alumno alumno = new Alumno();
		alumno = DaoFactory.getAlumno().getAlumnoById(Integer.parseInt(value));
		return alumno;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component,
			Object value) {
		if(value==null){
            return null;
        }
		String valor = String.valueOf(value);
		Alumno alumno = new Alumno();
		alumno = DaoFactory.getAlumno().getAlumnoById(Integer.parseInt(valor ));
		return alumno.getPersona().getNombre() + " " + alumno.getPersona().getApellido();
	}

}
